home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / vroom / framerate.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.1 KB  |  82 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <sys/time.h>
  18. #include <bstring.h>
  19. #include "framerate.h"
  20.  
  21. #define    DEFAULT_FRAME_RATE    10
  22.  
  23. static int        frameRate = DEFAULT_FRAME_RATE ;
  24. static float        frameTime = 1.f / DEFAULT_FRAME_RATE ;
  25. static struct timeval    frameStart ;
  26. static struct timeval    frameEnd ;
  27. static struct timeval    startTime ;
  28.  
  29.  
  30. /* BEGIN PROTOTYPES -S framerate.c */
  31. /* END PROTOTYPES -S framerate.c */
  32.  
  33. /*------------------------------------------------------------------------------
  34.  * Set the frame rate.
  35.  *----------------------------------------------------------------------------*/
  36. void
  37. setFrameRate(
  38.     int    newRate
  39.     )
  40. {
  41.     if( newRate > 0 )
  42.     {
  43.         frameRate = newRate ;
  44.         frameTime = 1.f / frameRate ;
  45.     }
  46. }
  47.  
  48.  
  49.  
  50. /*------------------------------------------------------------------------------
  51.  * Set the start time.
  52.  *----------------------------------------------------------------------------*/
  53. void
  54. initTime(
  55.     void
  56.     )
  57. {
  58.     struct timezone    tzp ;
  59.  
  60.     gettimeofday( &startTime, &tzp ) ;
  61. }
  62.  
  63.  
  64.  
  65. /*------------------------------------------------------------------------------
  66.  * Return the elapsed time since start time was called.
  67.  *----------------------------------------------------------------------------*/
  68. float
  69. gameTime(
  70.     void
  71.     )
  72. {
  73.     struct timeval    now ;
  74.     struct timezone    tzp ;
  75.  
  76.     gettimeofday( &now, &tzp ) ;
  77.  
  78.     return( (float)( ( now.tv_sec - startTime.tv_sec ) +
  79.         ( now.tv_usec - startTime.tv_usec ) / 1000000.f ) ) ;
  80. }
  81.  
  82.